import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeRouter from './home'
import CinemaRouter from './cinema'
import CartoonRouter from './cartoon'
import MineRouter from './mine'
import PhotoRouter from "./photo";
import WeChatRouter from "./wechat";
import WeiBoRouter from "./weibo";
import ChromeRouter from "./chrome";
import AdminRouter from "./admin"

Vue.use(VueRouter)

const routes = [
    HomeRouter, CinemaRouter, CartoonRouter, MineRouter, PhotoRouter, WeChatRouter, WeiBoRouter, ChromeRouter,AdminRouter,
    {
        path: '/',
        redirect: "/home"
    }
]

const router = new VueRouter({
    mode: "history",
    base: "god",
    routes
})

/* 解决：在VUE项目中点击两次路由切换 */
// const VueRouterPush = VueRouter.prototype.push 
// VueRouter.prototype.push = function push (to) {
//     return VueRouterPush.call(this, to).catch(err => err)
// }

/* // 路由中的守卫（全局守卫）
router.beforeEach((to, from, next) => {
    // console.log(to, from);
    let userObj = JSON.parse(localStorage.getItem("userObj")) || "[]";
    let obj = userObj.filter(item => item.isLogin === true)[0] || "{}"
    // console.log(obj)
    // 进入用户中心
    if(to.path === "/mine" || to.name === "mine") {
        // 判断用户是否登录了
        if(obj.isLogin) {
            console.log("mine");
            next();
        } else {
            next("/login")
        }
    } else {
        next();
    }
}) */

export default router
